home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 16 / bookmark.zip / BOOKMARK.M
Text File  |  1988-08-23  |  20KB  |  374 lines

  1. ;**************************************************************************
  2. ;*                                                                        *
  3. ;*    BOOKMARK.M              Larry DeMar         August 12, 1988         *
  4. ;*                                                                        *
  5. ;*    This facility manipulates Brief bookmarks in a "circular"           *
  6. ;*    fashion such that as new bookmarks are dropped they are added       *
  7. ;*    to the queue, and going from bookmark to bookmark may be done       *
  8. ;*    using "earliar_mark" and "later_mark" commands (similar to          *
  9. ;*    the way BRIEF buffers are traversed using Alt-n and Alt-minus).     *
  10. ;*                                                                        *
  11. ;*    These macros use the 10 bookmark system internal to Brief.          *
  12. ;*    This means that the bookmarks dropped will be saved and             *
  13. ;*    restored by the "restore" macro if used.  It also means that        *
  14. ;*    you may view (and goto) your bookmarks using <Alt-j><Tab>.          *
  15. ;*                                                                        *
  16. ;*    The purpose of this facility was to eliminate the need to           *
  17. ;*    deal with bookmarks by number.  Each time you drop a bookmark       *
  18. ;*    it is assigned the next successive number (first drop = 1,          *
  19. ;*    second drop = 2 etc.).  When any of the 4 macros in this            *
  20. ;*    package are called, the dropped bookmarks will be packed into       *
  21. ;*    the lowest positions available.  (This will only have an effect     *
  22. ;*    if a buffer containing bookmarks is deleted, if all of              *
  23. ;*    the files aren't available for restore, or if "out of order"        *
  24. ;*    bookmarks are dropped using Brief's <Alt-1> <Alt-2> etc.)           *
  25. ;*                                                                        *
  26. ;*    The 4 macros are:                                                   *
  27. ;*                                                                        *
  28. ;*    LED_DROP_MARK:    This will drop a bookmark at the current          *
  29. ;*                      cursor position.  It will assign the              *
  30. ;*                      next available bookmark number and                *
  31. ;*                      print a confirmation message (along with          *
  32. ;*                      a beep).  I like the confirmation beep            *
  33. ;*                      for dropping a mark....if you don't, its          *
  34. ;*                      the "(beep)" instruction in do_drop.              *
  35. ;*                                                                        *
  36. ;*                      If all 10 marks are in use, mark 1 will           *
  37. ;*                      be deleted, the other 9 will be shited            *
  38. ;*                      down 1 and the current cursor location            *
  39. ;*                      will become mark 10.                              *
  40. ;*                                                                        *
  41. ;*                      Marks dropped by this system (regardless          *
  42. ;*                      of buffer deletions and partial restores)         *
  43. ;*                      will always be in historical order (the           *
  44. ;*                      newest mark will have the highest number).        *
  45. ;*                                                                        *
  46. ;*    LED_HIGHEST_MARK: This will take you to the last bookmark           *
  47. ;*                      that was dropped (the newest).                    *
  48. ;*                                                                        *
  49. ;*    LED_EARLIER_MARK: This will take you to the next earlier mark       *
  50. ;*                      from the one last visited.  Note that alternate   *
  51. ;*                      use of LED_HIGHEST_MARK and LED_EARLIER_MARK      *
  52. ;*                      will take you back and forth between the 2        *
  53. ;*                      newest marks.  After going to mark 1,             *
  54. ;*                      LED_EARLIER_MARK takes you back to the highest    *
  55. ;*                      mark.                                             *
  56. ;*                                                                        *
  57. ;*    LED_LATER_MARK:   This will take you to the next later mark         *
  58. ;*                      from the one last visited.  After going           *
  59. ;*                      to the highest mark this takes you to             *
  60. ;*                      mark 1.  I don't use this, but provided           *
  61. ;*                      it for completeness. Going to the                 *
  62. ;*                      most recent mark and working your way             *
  63. ;*                      back works really well.                           *
  64. ;*                                                                        *
  65. ;*    Of course to make this useful at all, you need to assign these      *
  66. ;*    macros to keys.  Provide the following autoload statement in        *
  67. ;*    your initials macro:                                                *
  68. ;*                                                                        *
  69. ;*       (autoload "bookmark.cm" "led_drop_mark" "led_highest_mark"       *
  70. ;*                                  "led_later_mark" "led_earlier_mark")  *
  71. ;*                                                                        *
  72. ;*    and some key assignments (mine are based on an old editor I         *
  73. ;*    used to use.....I'm sure you can think of better mnemonic           *
  74. ;*    assignments):                                                       *
  75. ;*                                                                        *
  76. ;*       ;Ctrl-V drops a new bookmark.                                    *
  77. ;*       (assign_to_key "<Ctrl-v>" "led_drop_mark")                       *
  78. ;*                                                                        *
  79. ;*       ;Ctrl-Y goes to the last one dropped.                            *
  80. ;*       (assign_to_key "<Ctrl-y>" "led_highest_mark")                    *
  81. ;*                                                                        *
  82. ;*       ;Ctrl-E cycles back to earlier marks.                            *
  83. ;*       (assign_to_key "<Ctrl-e>" "led_earlier_mark")                    *
  84. ;*                                                                        *
  85. ;*       ;Ctrl-J cycles forward to later marks.                           *
  86. ;*       (assign_to_key "<Ctrl-j>" "led_later_mark")                      *
  87. ;*                                                                        *
  88. ;*    If anyone uses this and likes it, or has ideas for                  *
  89. ;*    improvement, please let me know on the Brief BBS.                   *
  90. ;*                                                                        *
  91. ;*                   Larry DeMar                                          *
  92. ;*                                                                        *
  93. ;**************************************************************************
  94.  
  95. ;**************************************************************************
  96. ;*                                                                        *
  97. ;*    LED_DROP_MARK                                                       *
  98. ;*                                                                        *
  99. ;*    This macro will drop a new mark.  FIND_FIRST_UNUSED will            *
  100. ;*    pack all existing marks and return the number we should             *
  101. ;*    use.  If all 10 marks are in use then we discard #1                 *
  102. ;*    and copy down marks 2-10.                                           *
  103. ;*                                                                        *
  104. ;**************************************************************************
  105. (macro led_drop_mark
  106.    (
  107.       (int goto_pointer)
  108.       (global goto_pointer)
  109.       (int mark_num)
  110.       (if (= mark_num (find_first_unused))
  111.           (
  112.              (do_drop mark_num)
  113.              (return 0)
  114.           )
  115.       )
  116. ;**************************************************************************
  117. ;*                                                                        *
  118. ;*    Now we need to copy all bookmarks down a step                       *
  119. ;*                                                                        *
  120. ;**************************************************************************
  121.       (int i)
  122.       (while (< i 9)
  123.          (copy_bookmark (+ i 2) (++ i))      ;from -- to
  124.       )
  125.       (do_drop 10)         ;now drop #10
  126.    )
  127. )
  128.  
  129. ;**************************************************************************
  130. ;*                                                                        *
  131. ;*    LED_HIGHEST_MARK                                                    *
  132. ;*                                                                        *
  133. ;*    This takes us to the highest mark.  FIND_HIGHEST packs              *
  134. ;*    all the marks and returns the highest used mark.                    *
  135. ;*    (0 if there are no marks).                                          *
  136. ;*                                                                        *
  137. ;**************************************************************************
  138. (macro led_highest_mark
  139.    (
  140.       (int last)
  141.       (if (= last (find_highest))            ;get highest book mark
  142.          (
  143.             (position_bookmark last)
  144.             (= goto_pointer last)
  145.          )
  146.          ;else
  147.          (
  148.             (beep)
  149.             (message "No bookmarks!")
  150.          )
  151.       )
  152.    )
  153. )
  154.  
  155. ;**************************************************************************
  156. ;*                                                                        *
  157. ;*    LED_EARLIER_MARK                                                    *
  158. ;*                                                                        *
  159. ;*    This takes us to the mark before the last one operated on           *
  160. ;*    (previously droped in history).  After visiting mark 1, the         *
  161. ;*    highest mark will be set again.                                     *
  162. ;*                                                                        *
  163. ;**************************************************************************
  164. (macro led_earlier_mark
  165.    (
  166.       (int last)
  167.  
  168.       (= last (find_highest))                ;get the highest mark.
  169.  
  170.       (if (|| (> goto_pointer last)    ;if goto pointer out of range
  171.               (! goto_pointer)         ;or if goto_pointer undefined
  172.           )
  173.           (  (led_highest_mark)
  174.              (return 0)
  175.           )
  176.       )
  177.       (if (-- goto_pointer)
  178.             (position_bookmark goto_pointer)
  179.          ;else
  180.             (led_highest_mark)            ;we wrapped around....back to highest
  181.       )
  182.    )
  183. )
  184.  
  185. ;**************************************************************************
  186. ;*                                                                        *
  187. ;*    LED_LATER_MARK                                                      *
  188. ;*                                                                        *
  189. ;*    Move to next mark (higher.....later in history), or go to           *
  190. ;*    first if you're on highest.                                         *
  191. ;*                                                                        *
  192. ;**************************************************************************
  193. (macro led_later_mark
  194.    (
  195.       (int last)
  196.       (if (!  (&& goto_pointer (= last (find_highest)))) ;pointer zero or no macros?
  197.           (  (led_highest_mark)              ;if un-initialized return highest
  198.              (return 0)                      ;if none, this will report the error.
  199.           )
  200.       )
  201.  
  202.       (if (> (++ goto_pointer) last)    ;if goto pointer left out after packing
  203.          (= goto_pointer 1)
  204.       )
  205.       (position_bookmark goto_pointer)
  206.    )
  207. )
  208.  
  209. ;**************************************************************************
  210. ;*                                                                        *
  211. ;*    COPY_BOOKMARK                                                       *
  212. ;*                                                                        *
  213. ;*    This macro copies a bookmark from 1 position to another.            *
  214. ;*    Its calling sequence is (copy_bookmark <source number>              *
  215. ;*                                          <destination number>)         *
  216. ;*                                                                        *
  217. ;**************************************************************************
  218. (macro copy_bookmark
  219.    (
  220.       (int buf line col)
  221.       (int from to)
  222.       (get_parm 0 from)
  223.       (get_parm 1 to)
  224.       (goto_bookmark from buf line col)  ;get #2
  225.       (drop_bookmark to "y" buf line col)
  226.    )
  227. )
  228.  
  229. ;**************************************************************************
  230. ;*                                                                        *
  231. ;*    DO_DROP                                                             *
  232. ;*                                                                        *
  233. ;*    This does the work to drop bookmark for its parameter number.       *
  234. ;*                                                                        *
  235. ;**************************************************************************
  236. (macro do_drop
  237.    (
  238.       (int drop_num)
  239.       (get_parm 0 drop_num)
  240.       (drop_bookmark drop_num "y")
  241.       (message "bookmark %d dropped" drop_num) 
  242.                                   ;
  243.       (beep)                      ;THIS IS THE LINE TO REMOVE IF YOU DON'T
  244.                                   ;WANT THE BEEP WHEN MARKS ARE DROPPED.
  245.                                   ;
  246.       (= goto_pointer drop_num)   ;"this is where we should goto"
  247.    )
  248. )
  249.  
  250. ;**************************************************************************
  251. ;*                                                                        *
  252. ;*    FIND_FIRST_UNUSED                                                   *
  253. ;*                                                                        *
  254. ;*    This macro finds the first unused bookmark                          *
  255. ;*    and returns the mark number 1-9.  If all bookmarks have             *
  256. ;*    been used, then it returns 0 (false).                               *
  257. ;*                                                                        *
  258. ;*    This macro is called somewhere in the sequence of all 4             *
  259. ;*    user level commands.  It has the side effect of packing             *
  260. ;*    all bookmarks into the lowest available slots.                      *
  261. ;*                                                                        *
  262. ;**************************************************************************
  263. (macro find_first_unused
  264.    (
  265.       (int buf line col val)
  266.       (int mark_to_check)
  267.       (= val 1)                                 ;make while go once.
  268.       (while val
  269.          (
  270.             (++ mark_to_check)                  ;start with 1
  271.             (if (== mark_to_check 11)
  272.                 (return 0)
  273.             )
  274.             (= val (goto_bookmark mark_to_check buf line col))
  275.          )
  276.       )
  277. ;**************************************************************************
  278. ;*                                                                        *
  279. ;*       we found a vacant slot.....see if there are any marks above us.  *
  280. ;*                                                                        *
  281. ;**************************************************************************
  282.       (int valid_one)
  283.       (while (= valid_one (find_above mark_to_check))
  284.          (
  285.             (copy_bookmark valid_one mark_to_check)   ;copy guy above us
  286.             (delete_bookmark valid_one)               ;get rid of that one
  287.             (++ mark_to_check)                        ;move to next spot
  288.          )
  289.       )
  290.       (return mark_to_check)
  291.    )
  292. )
  293.             
  294. ;**************************************************************************
  295. ;*                                                                        *
  296. ;*    FIND_ABOVE                                                          *
  297. ;*                                                                        *
  298. ;*    This is a utility for FIND_FIRST_UNUSED.  Once it finds the         *
  299. ;*    lowest unused, it needs to compress the rest of the bookmarks.      *
  300. ;*    We get as a parameter the number of the lowest vacant slot.         *
  301. ;*    We need to return the number of the lowest USED slot above          *
  302. ;*    the number passed to us (or zero for none).                         *
  303. ;*                                                                        *
  304. ;**************************************************************************
  305. (macro find_above
  306.    (
  307.       (int pointer)
  308.       (int buf line col)
  309.       (get_parm 0 pointer)
  310.       (while  (< (++ pointer) 11)
  311.          (if (goto_bookmark pointer buf line col)
  312.             (return pointer)
  313.          )
  314.       )
  315.       (return 0)
  316.    )
  317. )
  318.  
  319. ;**************************************************************************
  320. ;*                                                                        *
  321. ;*    DELETE_BOOKMARK                                                     *
  322. ;*                                                                        *
  323. ;*    This macro "deletes" a bookmark by assigning buffer, line           *
  324. ;*    and column to ZERO......THIS SEEMS TO WORK, BUT IS NOT              *
  325. ;*    SUPPORTED BY THE DOCUMENTATION...(There is no way given             *
  326. ;*    to "delete" a bookmark.)                                            *
  327. ;*                                                                        *
  328. ;**************************************************************************
  329. (macro delete_bookmark
  330.    (
  331.       (int bm)
  332.       (get_parm 0 bm)
  333.       (drop_bookmark bm "y" 0 0 0)
  334.    )
  335. )
  336.  
  337. ;**************************************************************************
  338. ;*                                                                        *
  339. ;*    POSITION_BOOKMARK                                                   *
  340. ;*                                                                        *
  341. ;*    This takes us to the bookmark number specified in the first         *
  342. ;*    argument.  The messages are in case it takes awhile to get          *
  343. ;*    there.                                                              *
  344. ;*                                                                        *
  345. ;**************************************************************************
  346. (macro position_bookmark
  347.    (
  348.       (int mark_num)
  349.       (get_parm 0 mark_num)
  350.       (message "Positioning Bookmark %d..." mark_num)
  351.       (goto_bookmark mark_num)
  352.       (message "Bookmark %d restored." mark_num)
  353.    )
  354. )
  355.  
  356. ;**************************************************************************
  357. ;*                                                                        *
  358. ;*    FIND_HIGHEST                                                        *
  359. ;*                                                                        *
  360. ;*    This routine is called to find the highest bookmark                 *
  361. ;*    in use (after compression).  It returns 0 if there are              *
  362. ;*    no bookmarks.                                                       *
  363. ;*                                                                        *
  364. ;**************************************************************************
  365. (macro find_highest
  366.    (
  367.       (int highest)
  368.       (if (! (= highest (find_first_unused)))   ;this is first UNUSED
  369.           (= highest 11)
  370.       )
  371.       (return (-- highest))         ;send back last USED
  372.    )
  373. )
  374.